SCRIPTING

Scripting Language Reference

ALERT <your message here>
Displays a simple alert window with an OK button (no icon, no beep) with the message that you type after ALERT. You can put the value of a variable in an alert by using $variable$.
Example:
ALERT You have $gold$ gold.

BEEP
Plays the alert sound set in the Sound control monitor (usually set at "Simple Beep").

DELAY
DELAY <lengthofdelay>
The DELAY without any parameter will delay until any currently playing sound (if any) is completed. If you put a number after DELAY from 1 to 1000 it will delay for that amount of time (100 = 1 second).

DOMENU ABOUT | NEW | OPEN | SAVE | QUIT
The DOMENU command is used with any one of the 5 menu choices (ABOUT, NEW, OPEN, SAVE, or QUIT) to execute either the "About" menu item in the "Apple" menu or one of the menu items in the "File" menu. The NEW, OPEN, and SAVE commands work even if you selected the "Use minimal menus" option in the "Game Options".
Example:
DOMENU OPEN

GOTOCARD <cardnumber>
Opens card numbered <cardnumber>. The <cardnumber> must be either a number or variable name. It can't be a card name since card names will be treated as a variable name.

HIDEBUTTON <buttonid>
Hides button number <buttonid>.

IF <trueExpression> THEN <dosomething>
If the statement after the IF is true, then the code after THEN will be executed. <dosomething> can be any other command except REM.
Examples:
IF X = 10 THEN SOUND Wild Eep
IF key <> 1 THEN ALERT You don't have the key.

IF <trueExpression> THEN
  ' do something
ELSE
  ' do something else
END IF
This is a block IF command. If the satement after the IF is true, then all of the lines lines between IF and ELSE are executed. If the satement after the IF is false, then all of the lines between ELSE and END IF are executed. ELSE is optional and only needs to be used if you want statements to be executed when the IF line is false.
Example:
IF X = 100 THEN
  SOUND You Win
  GOTOCARD 99
ELSE
  SOUND You Lose
  GOTOCARD 100
END IF

LOOP MOVIE <x>
Loops a currently playing QuickTime MIDI, wav, or Quicktime movie with no movie data x amount of times or until either another movie is played or a STOP MOVIE command is executed. You can leave out the x if you want the movie to loop an infinate number of times. This command should normally be placed on the line after a MOVIE command. This command does not currently work on QuickTime movies with a movie track.

LOOP SOUND <x>
Loops the currently playing sound (or the last sound to be played) x amount of times or until either another sound is played or a STOP SOUND command is executed. You can leave out the x if you want the sound to loop an infinate number of times. This command should normally be placed on the line after a SOUND command.

MOVIE <horz> <vert> <nameofmovie>
Plays a QuickTime movie file named <nameofmovie> at location <horz>, <vert> in the graphics area of the current card. Movies will only play if QuickTime v2.0 or better is installed and the movie file is in the same folder as your game. Coordinates for <horz> and <vert> must be numbers. They can't be variables. You can also play MIDI and wav files with the MOVIE command.

NOTE <frequency> <length> <volume>
Plays any of the standard MIDI notes. <frequency> is the pitch and must be a number from 1 to 127. <length> must be a number indicating how long the note will continue playing. The length is 60 per second, not 100 per second as the DELAY command is. <volume> must be from 0 to 127 and indicates the sound volume you want to use. The volume paramter is optional. If you don't set the volume then it will default to 127 (loud).

ON TIMER <time> GOTOCARD <cardnumber>
Branches to card <cardnumber> after <time> amount of time has elapsed (100 = 1 second). This only works while on the card the command was executed from. Once the game branches to another card, the TIMER is set to off. See also the TIMER OFF command.

RANDOM <rand1> <rand2> <rand3> <rand4> <rand5>
Lets you choose a random number. You can have from 1 to 5 parameters. If there is only one number after RANDOM, a random number from 1 to <rand1> will be chosen. If there is 2 to 5 numbers, then a random one of those numbers will be selected.
Examples:
Pick a random number from 1 to 25 and put it in X:
  X = RANDOM 25
Randomly pick either 10, 15, or 18 and put it in X:
  X = RANDOM 10 15 18

REM
This is used for remarks that you want to put in your code possible to remind yourself what a certain piece of code is for. Any line starting with REM (you can also use the ' apostrophy character rather than REM) will be ignored. This must be at the beginning of a line of code. Remarks cannot be put in the middle of a line.

RESET
Resets all variables to 0. It's usually a good idea to put this as the first line of the Card Script in card #1 so that anytime a player starts a new game, all variables will be reset. If you need some variables to start with a value other than 0, set them after using RESET.

SHOWBUTTON <buttonid>
Shows button number <buttonid> if it was previously hidden using HIDEBUTTON.

SOUND <soundname>
Plays the sound named <soundname>.

STATUSBAR <amount> <cardnumber>
Adds <amount> to the status bar. A negative number moves the bar to the left and a positive number moves the bar to the right. The <cardnumber> is the card that GameMaker should go to if the bar is at 0 after adding <amount> to the bar.

STOP SOUND | MOVIE
Stops playing either a sound or a QuickTime file that only has a sound track (including MIDI or wav files). It does not work with the NOTE command or QuickTime movies that have movie data.
Examples:
Stop playing a sound:
  STOP SOUND
Stop playing a QuickTime file:
  STOP MOVIE
Stop playing both a sound and a movie:
  STOP SOUND MOVIE

SWAP <variable1> <variable2>
Exchanges the value of 2 variables. If variable1 = 10 and variable2 = 20, doing a swap will set variable1 to 20 and variable2 to 10.

TIMER OFF
Turns off the TIMER if it was on. See the ON TIMER command for instructions on using the TIMER.

TOGGLE <variable>
Toggles variable between 0 and 1. If variable = anything other than 0 then it's set to 0. If variable = 0 then it's set to 1.

----------
VARIABLES
----------
Variables are createed in your code, not in another window ahead of time. So if you have a Button code that has:
  key = 1
That will create a variable named key that is equal to 1. All variables are global so you can then test to see if key = 1 in any other Button, Card, or Click Area code. You can make a variable equal to any number from -32767 to 32767. So lets say you have a button named "Get key". When a player clicks on the button, it executes your code. You could have something simple like this:
  IF key = 1 THEN ALERT You already have the key.
  key = 1
The above code will show an alert message window if the key was already set to 1. It will then set the key to 1 in case it wasn't = to 1. The idea here is that you are keeping your own an inventory list. You can then check to see if the player has the key when they are on another card. Later in the game there can be a button named "Open Door". The code for that button can then check to see if the player got the key earlier in the game.
  IF key = 1 THEN GOTOCARD 100
  IF key = 0 THEN ALERT You need a key to unlock the door.

You can also make variables equal to other variables and you can add or subtract from them:
  gold = gold + 10
  experience = gold * 2

The limitations of variables are as follows:
-There is a maximum of 50 different variables in each project.
-There are no string variables except as used in the ALERT command.
-Variables must be integers in the range of -32767 and 32767.
-Complex math is not supported and parenthesis are not allowed. For example, X = Y + 5 will work fine, but X = Y + (Z * 5) will not.
-There must be a space between names, numbers, and signs. For example:
  gold=gold+10
will not work because there needs to be spaces between each item, but it may not generate an error either, so you should be careful when writing these lines. This will hopefully improve in the future. The correct way to write it is:
  gold = gold + 10

--------------------
BUILT-IN VARIABLES
--------------------
Counter
The value of this variable will be displayed in the bottom right of the main window if you have enabled the Counter in the "Game Options" menu. The display will automatically be updated whenever you change its value in any of the scripts.

Barvalue
This variable returns the current value of the Status Bar. You can also use it to set the value of the Status Bar. For other ways of using the Status Bar, see the STATUSBAR command.

Recentcard
This variable always returns the number of the most recent card that the player was on. It should not be directly changed in scripts.